<?php

namespace app\admin\controller;

use buildView\Actions;
use buildView\Grid;
use think\Controller;
use buildView\Form;
use app\shop\model\ShopGoodsCate;
use app\common\model\ShopStore;

class StoreCate extends Controller
{
    public function index($store_id)
    {
        $grid = new Grid(new ShopGoodsCate);
        $storeData = ShopStore::where('id',$store_id)->find();
        $grid->setTitle($storeData['name'].'--分类管理');
        $grid->model()->where('pid','>',0)->where('sid',$store_id)->order('sort asc,id desc');
        $grid->title('分类名称');
        $grid->status('是否显示')->switchs();
        $grid->create_at('创建时间');
        $grid->hideExportButton();
        $grid->setFromOpen();
        $grid->actions(function (Actions $action) {
            $action->hideDetail();
        });
        // 设置添加按钮参数
        $grid->setAddButtonParam(['store_id'=>$store_id]);
        // 设置编辑按钮参数
        $grid->setEditButtonParam(['store_id'=>$store_id]);
        return $grid->view();
    }

    public function form($store_id)
    {
        $cates = ShopGoodsCate::field('id,title,pid')->where('pid', 0)->where('id',18)->column('title','id');
        $form = new Form(new ShopGoodsCate);
        // 隐藏框框 默认sid = $store_id
        $form->hidden('sid', '门店id')->default($store_id);
        $form->text('title','分类名称')->required();
        $form->select('pid', '父级分类')->options($cates)->default(1);
        return $form->view();
    }


}
